<script language="JavaScript1.2">
	/* Constant Variables */
	var 
		AVAILABLETABLE_TABLE=0,
		AVAILABLETABLE_LEVEL=1,
		TABLEFIELD_TABLE=0,
		TABLEFIELD_FIELD=1,
		TABLEFIELD_TYPE=2,
		TABLEFIELD_PICKLIST=3,
		TABLEFIELD_LKUPTABLE=4,
		TABLEFIELD_LKUPKEY=5,
		TABLEFIELD_LKUPRESULT=6,
		TABLEFIELD_LKUPKEYSIZE=7,
		TABLEFIELD_DESC=8,
		SELECTEDTABLE_TABLE=0,
		SELECTEDTABLE_LEVEL=1,
		SELECTEDTABLE_ALIAS=2,
		DROP_FLDNAME=0,
		DROP_FLDDESC=1,
		CONDITION_PRIORITYNO=0,
		CONDITION_ALIASSOURCE=1,
		CONDITION_FIELDSOURCE=2,
		CONDITION_ALIASJOINING=4,
		CONDITION_GROUPSTART=7,
		CONDITION_GROUPEND=8,
		SELECTEDFIELD_FIELDNAME=0,
		SELECTEDFIELD_ALIAS=1,
		SELECTEDFIELD_AGGREGATE=2,
		SELECTEDFIELD_HEADERNAME=3,
		SELECTEDFIELD_DATECONVFUNC=4,
		SELECTEDFIELD_WRAPON=5,
		SELECTEDFIELD_SUPRESSZERO=6,
		SELECTEDFIELD_NUMBERFORMAT=7,
		ORDERBY_ALIASFLDNAME=0,
		ORDERBY_ORDER=1,
		GROUPHEADER_FIELDALIAS=0,
		GROUPHEADER_CAPTION=1,
		GROUPHEADER_ALIAS=2,
		GROUPHEADER_FIELD=3,
		GROUPHEADER_FUNCTION=4,
		GROUPFOOTER_CAPTION=0,
		GROUPFOOTER_ALIAS=1,
		GROUPFOOTER_FIELD=2,
		GROUPFOOTER_AGGREGATE=3,
		PAGEFOOTER_ALIAS=0,
		PAGEFOOTER_FIELD=1,
		GRANDFOOTER_ALIAS=0,
		GRANDFOOTER_FIELD=1,

		DELIMITER="~",
		aSelectedTable=new Array(), aSelectedField=new Array(),
		nSelectedTableLen=0, nFld_FieldLen=0, nSelectedFieldLen=0,
		nSourceFieldLen=0, nConditionLen=0,
		nGroupByLen=0, nOrderByLen=0, sSourceValue,
		nGroupHeaderLen=0, nHeaderTableLen=0, nFooterTableLen=0,
		nGroupFooterLen=0, nPageFooterLen=0, nPageTableLen=0,
		nGrandFooterLen=0, nGrandTableLen=0;

	function InitVar() {
			nSourceFieldLen=document.frmSchedView.sourcefield.options.length;
			nConditionLen=document.frmSchedView.condition.options.length;
	}

	function CreateAlias() {
	var nCnt, aTemp, sUseAlias="", sFreeAlias, ALIASSET="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	
		for (nCnt=0; nCnt < nSelectedTableLen; nCnt++) {
			aTemp=document.frmSchedView.selectedtable.options[nCnt].value.split(DELIMITER)
			sUseAlias=sUseAlias + aTemp[SELECTEDTABLE_ALIAS]
		}
	
		for (nCnt=0; nCnt < ALIASSET.length; nCnt++) {
			sFreeAlias=ALIASSET.charAt(nCnt)
	
			if (sUseAlias.indexOf(sFreeAlias) == -1)
				return (sFreeAlias)
		}
	}
	//}}}
	//{{{ function Triming
	function Trim(s)
	{
	  // Remove leading spaces and carriage returns
	
	  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	  {
	    s = s.substring(1,s.length);
	  }
	
	  // Remove trailing spaces and carriage returns
	
	  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	  {
	    s = s.substring(0,s.length-1);
	  }
	  return s;
	}
	//}}}
	//{{{ function SelectTable
	function SelectTable() {
	var oAvailableTable=document.frmSchedView.availabletable,
		oSelectedTable=document.frmSchedView.selectedtable, optionSelectedTable,
		oSourceTable=document.frmSchedView.sourcetable, optionSourceTable,
		nIndex=oAvailableTable.selectedIndex, sFreeAlias, lAdded=false,
		nCnt, sValue, sText, nPos, aTemp
	
		if (nIndex != -1) {
			aTemp=oAvailableTable.options[nIndex].value.split(DELIMITER)
	
			// Check if table has database level
			if (aTemp[AVAILABLETABLE_LEVEL].replace(" ", "") == "")
				alert("Table doesn't have database level.")
			else {
				sText=aTemp[AVAILABLETABLE_TABLE]
	
				// Check if table has already been added to the list
				// We have to use array instead of the select object to avoid errors.
				for (nCnt=0; nCnt < nSelectedTableLen; nCnt++) {
					if (sText == aSelectedTable[nCnt]) {
						lAdded=true
						break
					}
				}
	
				if (!lAdded) {
					sFreeAlias=CreateAlias()
					sValue=oAvailableTable.options[nIndex].value + DELIMITER + sFreeAlias
					aSelectedTable[nSelectedTableLen]=sText
					optionSelectedTable=new Option(sText + " (" + sFreeAlias + ")", sValue)
					optionSourceTable=new Option(sText, sText)
					oSelectedTable.options[nSelectedTableLen]=optionSelectedTable
					oSourceTable.options[nSelectedTableLen]=optionSourceTable
					nSelectedTableLen++
	
					if (nSelectedTableLen == 1) {
						nSourceFieldLen=fillTableFields(document.frmSchedView.sourcetable,document.frmSchedView.sourcefield)
					}
				}
			} // check for database level
		} // check for selected items in available tables
	}
	///}}}
	//{{{ function RemoveTable
	function RemoveTable() {
	var oSelectedTable=document.frmSchedView.selectedtable,
		oCondition=document.frmSchedView.condition,
		oSelectedField=document.frmSchedView.selectedfield,
		oSourceTable=document.frmSchedView.sourcetable,
		aTemp, nCnt, nIndex, nCounter, aTable2Delete, aField2Delete,
		sGroupStart, sEndStart, lRemoveGrouping=false, lHasChange=false,
		aFootTemp, nInnCnt, sNewValue
	
		while (true) {
			for (nCnt=0; nCnt < nSelectedTableLen; nCnt++) {
				if (oSelectedTable.options[nCnt].selected)
					break
			}
	
			if (nCnt < nSelectedTableLen) {
				aTable2Delete=oSelectedTable.options[nCnt].value.split(DELIMITER)
				oSelectedTable.options[nCnt]=null
				//oFld_TableDrop.options[nCnt]=null
				oSourceTable.options[nCnt]=null
				nIndex=nCnt
				nCounter=0
				aTemp=new Array()
	
				for (nCnt=0; nCnt < nSelectedTableLen; nCnt++) {
					if (nIndex != nCnt)
						aTemp[nCounter++]=aSelectedTable[nCnt]
				}
	
				aSelectedTable=aTemp
				nSelectedTableLen--
	
				if (nSelectedTableLen != 0) {
					nSourceFieldLen=fillTableFields(document.frmSchedView.sourcetable,document.frmSchedView.sourcefield)
				} else {
					nFld_FieldLen=ClearSelectItems(nFld_FieldLen, document.frmSchedView.fld_field)
					nSourceFieldLen=ClearSelectItems(nSourceFieldLen, document.frmSchedView.sourcefield)
				}
	
				//-- Cascade delete to selectedfield ---
				nCnt=0
				while (nCnt < nSelectedFieldLen) {
					aField2Delete=oSelectedField.options[nCnt].value.split(DELIMITER)
	
					if (	aTable2Delete[SELECTEDTABLE_ALIAS] ==
							aField2Delete[SELECTEDFIELD_ALIAS]) {
						oSelectedField.options[nCnt].selected=true
						RemoveField(false)
						nCnt=0
					} else
						nCnt++
				}
	
				//--- Cascade delete to conditions ---
				nCnt=0
				while (nCnt < nConditionLen) {
					aField2Delete=oCondition.options[nCnt].value.split(DELIMITER)
	
					if ( (aTable2Delete[SELECTEDTABLE_ALIAS] == aField2Delete[CONDITION_ALIASSOURCE]) ||
						 (aField2Delete[CONDITION_ALIASJOINING] == aTable2Delete[SELECTEDTABLE_ALIAS])
					   ) {
						sGroupStart=aField2Delete[CONDITION_GROUPSTART].replace(/ /g, "")
						sEndStart=aField2Delete[CONDITION_GROUPEND].replace(/ /g, "")
	
						if (!lRemoveGrouping && sGroupStart.length != sEndStart.length)
							lRemoveGrouping=true
	
						oCondition.options[nCnt]=null
						nConditionLen--
						nCnt=0
					} else
						nCnt++
				}
			} else
				break
		}
	}
	//}}}
	//{{{ function fillTableFields
	function fillTableFields(oObjectTable, oObjectField) {
	var oTableObject=oObjectTable,
		sTablename=oTableObject.options[oTableObject.selectedIndex].text,
		oTableField=document.frmSchedView.tablefield,
		oTableObjectField=oObjectField, optionTableObjectField,
		nCnt, sField, aTemp, sValue
		nTableFieldLen = oTableField.options.length
	
		nTableFieldLen=ClearSelectItems(nTableFieldLen, oTableObjectField)
	
		if (sTablename != " ") {
			for (nCnt=0; nCnt < oTableField.options.length; nCnt++) {
				sValue=oTableField.options[nCnt].value
				aTemp=sValue.split(DELIMITER)
	
				if (aTemp[TABLEFIELD_TABLE] == sTablename) {
					sField=aTemp[TABLEFIELD_FIELD]
					optionTableObjectField=new Option(sField, sField)
					oTableObjectField.options[nTableFieldLen++]=optionTableObjectField
				}
			}
		}
	
		ChangeSourceValue()
		//ToggleJoin()
		return nTableFieldLen;
	}
	//}}}
	//{{{ function CascadeTableDelete
	function CascadeTableDelete(nObjectLen, sAlias, oObject, nIndex) {
	var nCnt=0, sObjectAlias, aTemp
	
		while (nCnt < nObjectLen) {
			if ((typeof nIndex) == "undefined")
				sObjectAlias=oObject.options[nCnt].value.substring(0, 1)
			else {
				aTemp=oObject.options[nCnt].value.split(DELIMITER)
				sObjectAlias=aTemp[nIndex]
			}
	
			if (sAlias == sObjectAlias) {
				oObject.options[nCnt]=null
				nObjectLen--
				nCnt=0
			} else
				nCnt++
		}
	
		return(nObjectLen)
	}
	//}}}
	//{{{ function ClearSelectItems
	function ClearSelectItems(nItemsLen, oSelect) {
		while (nItemsLen != 0)
			oSelect.options[--nItemsLen]=null
	
		return(nItemsLen)
	}
	//}}}
	//{{{ function GetAlias
	function GetAlias(sTablename) {
		return "A"
	}
	//}}}
	//{{{ function GetTableName
	function GetTableName(sAlias) {
	var nCnt, aTemp
	
		with (document.frmSchedView) {
			for (nCnt=0; nCnt < nSelectedTableLen; nCnt++) {
				aTemp=selectedtable.options[nCnt].value.split(DELIMITER)
	
				if (aTemp[SELECTEDTABLE_ALIAS] == sAlias)
					return (aTemp[SELECTEDTABLE_TABLE])
			}
		}
	}
	//}}}
	//{{{ function SelectField
	function SelectField() {
	var nIndex=document.frmSchedView.fld_field.selectedIndex,
		oFld_TableDrop=document.frmSchedView.fld_tabledrop,
		oAggregate=document.frmSchedView.aggregate,
		sAggregate=oAggregate.options[oAggregate.selectedIndex].value,
		sConvertDate=document.frmSchedView.convertdate.options[document.frmSchedView.convertdate.selectedIndex].value,
		sHeaderName=document.frmSchedView.headername.value,
		sNumberformat=document.frmSchedView.numberformat.value,
		oGroupBy=document.frmSchedView.groupby, optionGroupBy,
		oSelectedField=document.frmSchedView.selectedfield, optionSelectedField,
		oConvertDate=document.frmSchedView.convertdate,
		nCnt, sValue, nPos, sText, sAlias, lAdded=false,
		aTemp, nInnerCnt, sFQGroupBy, lGroupByExist, lWithAggregates,
		oFooterTable=document.frmSchedView.footertable, optionFooterTable,
		oPageTable=document.frmSchedView.pagetable, optionPageTable,
		oGrandTable=document.frmSchedView.grandtable, optionGrandTable,
		oWrapOn=document.frmSchedView.wrapon, sCurrentFieldDataType,
		oDecimal=document.frmSchedView.decimalplace, sSupressZero
	
		aTemp=document.frmSchedView.fld_field.options[nIndex].value.split(DELIMITER)
		sCurrentFieldDataType=GetColumnType(oFld_TableDrop.options[oFld_TableDrop.selectedIndex].value, aTemp[DROP_FLDNAME]).replace(" ", "")
	
		if (nIndex != -1) {
			if (oConvertDate.options[oConvertDate.selectedIndex].value != " " &&
				sCurrentFieldDataType != "ftdatetime")
				alert(aTemp[DROP_FLDNAME] + " is not a date field.")
			else
				if (sCurrentFieldDataType == "")
					alert("Field doesn't have datatype. \n Please contact your iBOS/e Administrator.")
				else {
					sAlias=GetAlias(oFld_TableDrop.options[oFld_TableDrop.selectedIndex].value)
					sValue=aTemp[DROP_FLDNAME]
	
					// Check if field has already been added to the list
					// We have to use array instead of the select object to avoid errors.
					for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
						if (sAlias + sValue == aSelectedField[nCnt]) {
							lAdded=true
							break
						}
					}
	
					if (!lAdded) {
						sText=sAlias + sValue
	
						if (sConvertDate != " ")
							sText=sConvertDate + "(" + sText + ")"
	
						if (sAggregate != " ")
							sText=sAggregate + "(" + sText + ")"
	
						if (sHeaderName != "")
							sText=sText + " AS " + sHeaderName
						else
							sHeaderName=' '
	
						if (document.frmSchedView.supresszero.checked)
							sSupressZero="Y"
						else
							sSupressZero="N"
	
						if (sNumberformat == "")
							sNumberformat=' '
	
						aSelectedField[nSelectedFieldLen]=sAlias + sValue
						optionSelectedField=new Option(sText,
							sValue + DELIMITER + sAlias + DELIMITER +
							sAggregate + DELIMITER + sHeaderName +
							DELIMITER + sConvertDate + DELIMITER +
							oWrapOn.options[oWrapOn.selectedIndex].value + DELIMITER +
							sSupressZero + DELIMITER + sNumberformat)
						oSelectedField.options[nSelectedFieldLen++]=optionSelectedField
	
						// check for aggregates in the fields
						lWithAggregates=false
						for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
							aTemp=oSelectedField.options[nCnt].value.split(DELIMITER)
							if (aTemp[SELECTEDFIELD_AGGREGATE] != " ") {
								lWithAggregates=true
								break
							}
						}
	
						if (lWithAggregates) {
							// update the group by field
							for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
								aTemp=oSelectedField.options[nCnt].value.split(DELIMITER)
								sFQGroupBy=aTemp[SELECTEDFIELD_ALIAS] + aTemp[SELECTEDFIELD_FIELDNAME]
	
								if (aTemp[SELECTEDFIELD_AGGREGATE] == " ") {
									// check if field has already been added to group by field
									lGroupByExist=false
									for (nInnerCnt=0; nInnerCnt < nGroupByLen; nInnerCnt++) {
										if (oGroupBy.options[nInnerCnt].value == sFQGroupBy) {
											lGroupByExist=true
											break
										}
									}
	
									if (!lGroupByExist) {
										optionGroupBy=new Option(sFQGroupBy, sFQGroupBy)
										oGroupBy.options[nGroupByLen++]=optionGroupBy
									}
								}
							}
						}
	
						optionFooterTable=new Option(sAlias + sValue, sAlias + sValue)
						oFooterTable.options[nFooterTableLen++]=optionFooterTable
						optionPageTable=new Option(sAlias + sValue, sAlias + sValue)
						oPageTable.options[nPageTableLen++]=optionPageTable
						optionGrandTable=new Option(sAlias + sValue, sAlias + sValue)
						oGrandTable.options[nGrandTableLen++]=optionGrandTable
					}
				} // check for field datatype
		} // check selected items in available fields
	}
	//}}}
	//{{{ function SelectOrder
	function SelectOrder() {
	var nCnt, oSelectedField=document.frmSchedView.selectedfield, aTemp,
		sAliasFldName, nInnCnt, oOrderBy=document.frmSchedView.orderby,
		lOrderByExist, optionOrderBy, aTemp2, sChronoOrder, sChronoCode,
		oHeaderTable=document.frmSchedView.headertable, optionHeaderTable
	
		for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
			if (oSelectedField.options[nCnt].selected) {
				aTemp=oSelectedField.options[nCnt].value.split(DELIMITER)
				sAliasFldName=aTemp[SELECTEDFIELD_ALIAS] + aTemp[SELECTEDFIELD_FIELDNAME]
	
				if (aTemp[SELECTEDFIELD_AGGREGATE] == " ") {
					lOrderByExist=false
	
					for (nInnCnt=0; nInnCnt < nOrderByLen; nInnCnt++) {
						aTemp2=oOrderBy.options[nInnCnt].value.split(DELIMITER)
	
						if (aTemp2[ORDERBY_ALIASFLDNAME] == sAliasFldName) {
							lOrderByExist=true
							break
						}
					} // check if field already exist in order by
	
					if (!lOrderByExist) {
						if (document.frmSchedView.chronoorder[0].checked) {
							sChronoOrder="ASC"
							sChronoCode="A"
						} else {
							sChronoOrder="DESC"
							sChronoCode="D"
						}
	
						optionOrderBy=new Option(sAliasFldName + " " + sChronoOrder, sAliasFldName + DELIMITER + sChronoCode)
						oOrderBy.options[nOrderByLen++]=optionOrderBy
						optionHeaderTable=new Option(sAliasFldName, sAliasFldName)
						oHeaderTable.options[nHeaderTableLen++]=optionHeaderTable
					}
				} else
					alert(sAliasFldName + " is invalid in the Order By Clause \nbecause it is not contained in either an aggregate function or the \nGroup By Clause.") // check if field is aggregate
			} // check if item in selected fields is selected
		} // loop selected fields
	}
	//}}}
	//{{{ fucntion RemoveField
	function RemoveField(lCascade) {
	var oSelectedField=document.frmSchedView.selectedfield,
		oGroupBy=document.frmSchedView.groupby,
		oOrderBy=document.frmSchedView.orderby,
		oHeaderTable=document.frmSchedView.headertable,
		oFooterTable=document.frmSchedView.footertable,
		oGroupFooter=document.frmSchedView.groupfooter,
		oPageTable=document.frmSchedView.pagetable,
		oPageFooter=document.frmSchedView.pagefooter,
		oGrandTable=document.frmSchedView.grandtable,
		oGrandFooter=document.frmSchedView.grandfooter,
		oCondition=document.frmSchedView.condition,
		aTemp, nCnt, nIndex, nCounter, aValue, sAsField,
		sFQGroupBy, aTemp2, lWithAggregates, aField2Delete
	
		while (true) {
			for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
				if (oSelectedField.options[nCnt].selected)
					break
			}
	
			if (nCnt < nSelectedFieldLen) {
				aValue=oSelectedField.options[nCnt].value.split(DELIMITER)
				oSelectedField.options[nCnt]=null
				nIndex=nCnt
				nCounter=0
				aTemp=new Array()
	
				for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
					if (nIndex != nCnt)
						aTemp[nCounter++]=aSelectedField[nCnt]
				}
	
				aSelectedField=aTemp
				nSelectedFieldLen--
				sAsField=aValue[SELECTEDFIELD_ALIAS] + aValue[SELECTEDFIELD_FIELDNAME]
	
				if (lCascade) {
					//--- Cascade delete to group by---
					if (CascadeFieldDelete(nGroupByLen, oGroupBy, sAsField))
						nGroupByLen--
					//--- Cascade delete to order by ---
					if (CascadeFieldDelete(nOrderByLen, oOrderBy, sAsField))
						nOrderByLen--
					//--- Cascade delete to header table ---
					if (CascadeFieldDelete(nHeaderTableLen, oHeaderTable, sAsField))
						nHeaderTableLen--
					//--- Cascade delete to footer table ---
					if (CascadeFieldDelete(nFooterTableLen, oFooterTable, sAsField))
						nFooterTableLen--
					//--- Cascade delete to page table ---
					if (CascadeFieldDelete(nPageTableLen, oPageTable, sAsField))
						nPageTableLen--
					//--- Cascade delete to grand table ---
					if (CascadeFieldDelete(nGrandTableLen, oGrandTable, sAsField))
						nGrandTableLen--
					//--- Cascade delete to groupings ---
					CascadeDelete2GroupHeader(sAsField)
					UpdateFooter()
					//--- Cascade delete to page footer ---
					nCnt=0
					while (nCnt < nPageFooterLen) {
						aField2Delete=oPageFooter.options[nCnt].value.split(DELIMITER)
	
						if (aValue[SELECTEDFIELD_ALIAS] == aField2Delete[PAGEFOOTER_ALIAS] &&
							aValue[SELECTEDFIELD_FIELDNAME] == aField2Delete[PAGEFOOTER_FIELD]) {
							oPageFooter.options[nCnt]=null
							nPageFooterLen--
							nCnt=0
						} else
							nCnt++
					}
					//--- Cascade delete to grand footer ---
					nCnt=0
					while (nCnt < nGrandFooterLen) {
						aField2Delete=oGrandFooter.options[nCnt].value.split(DELIMITER)
	
						if (aValue[SELECTEDFIELD_ALIAS] == aField2Delete[GRANDFOOTER_ALIAS] &&
							aValue[SELECTEDFIELD_FIELDNAME] == aField2Delete[GRANDFOOTER_FIELD]) {
							oGrandFooter.options[nCnt]=null
							nGrandFooterLen--
							nCnt=0
						} else
							nCnt++
					}
					//--- dont cascade delete to conditions
					//--- fields in conditions can exist even if not
					//--- present in select clause
				}
	
				if (aValue[SELECTEDFIELD_AGGREGATE] != " ") {
					// check for aggregates in the fields
					lWithAggregates=false
					for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
						aTemp=oSelectedField.options[nCnt].value.split(DELIMITER)
						if (aTemp[SELECTEDFIELD_AGGREGATE] != " ") {
							lWithAggregates=true
							break
						}
					}
					// remove group by field
					if (!lWithAggregates)
						nGroupByLen=ClearSelectItems(nGroupByLen, oGroupBy)
				}
			} else
				break
		}
	}
	//}}}
	//{{{ function RemoveOrder
	function RemoveOrder() {
	var nCnt, aTemp
	
		with (document.frmSchedView) {
			while (true) {
				for (nCnt=0; nCnt < nOrderByLen; nCnt++) {
					if (orderby.options[nCnt].selected)
						break
				}
	
				if (nCnt < nOrderByLen) {
					aTemp=orderby.options[nCnt].value.split(DELIMITER)
					orderby.options[nCnt]=null
					nOrderByLen--
					//--- Cascade delete to header table by ---
					if (CascadeFieldDelete(nHeaderTableLen, headertable, aTemp[ORDERBY_ALIASFLDNAME]))
						nHeaderTableLen--
					//--- Cascade delete to group header by ---
					CascadeDelete2GroupHeader(aTemp[ORDERBY_ALIASFLDNAME])
					UpdateFooter()
				} else
					break
			}
		}
	}
	//}}}
	//{{{ fucntion CascadeDelete2GroupHeader
	function CascadeDelete2GroupHeader(sAliasField) {
	var nCnt=0, aFootTemp, sNewValue, lHasChange, nInnCnt
	
		with (document.frmSchedView) {
			while (nCnt < nGroupHeaderLen) {
				aFootTemp=groupheader.options[nCnt].value.split(DELIMITER)
	
				if (sAliasField == aFootTemp[GROUPHEADER_FIELDALIAS]) {
					groupheader.options[nCnt]=null
					nGroupHeaderLen--
					nCnt=0
					lHasChange=true
				} else {
					// check the footer also
					sNewValue=aFootTemp[GROUPHEADER_FIELDALIAS]
					lHasChange=true
	
					for (nInnCnt=2; nInnCnt < aFootTemp.length; nInnCnt=nInnCnt+4) {
						if (aFootTemp[nInnCnt] + aFootTemp[nInnCnt + 1] != sAliasField) {
							sNewValue=sNewValue + DELIMITER + aFootTemp[nInnCnt - GROUPHEADER_CAPTION] + DELIMITER +
								aFootTemp[nInnCnt] + DELIMITER +
								aFootTemp[nInnCnt + 1] + DELIMITER +
								aFootTemp[nInnCnt + 2]
						}
					}
	
					groupheader.options[nCnt].value=sNewValue
					nCnt++
				}
			}
	
			if (lHasChange)
				if (nGroupHeaderLen != 0)
					groupheader.options[0].selected=true
				else
					nGroupFooterLen=ClearSelectItems(nGroupFooterLen, groupfooter)
		}
	}
	//}}}
	//{{{ function CascadeFieldDelete
	function CascadeFieldDelete(nLen, oItem, sValue) {
	var nCnt, lDeleted=false
	
		for (nCnt=0; nCnt < nLen; nCnt++) {
			if (oItem.options[nCnt].value == sValue ||
				oItem.options[nCnt].value.substring(0, sValue.length + 1) == sValue + DELIMITER) {
					oItem.options[nCnt]=null
					lDeleted=true
					break
			}
		}
		return (lDeleted)
	}
	//}}}
	//{{{ function GetSourceField
	function GetSourceField(nLen, oObject, lFirst, oSourceTable) {
	var oTableField=document.frmSchedView.sourcetable,
		optionSourceField, nCnt, sField, aTemp
	
		nLen=ClearSelectItems(nLen, oObject)
	
		if (oSourceTable.selectedIndex != -1) {
			for (nCnt=0; nCnt < oTableField.options.length; nCnt++) {
				aTemp=oTableField.options[nCnt].value.split(DELIMITER)
	
				if (aTemp[TABLEFIELD_TABLE] == oSourceTable.text) {
	
					if (lFirst) {
						SourceValue(aTemp)
						lFirst=false
					}
	
					sField=aTemp[TABLEFIELD_FIELD]
					optionSourceField=new Option(sField, sField)
					oObject.options[nLen++]=optionSourceField
				}
			}
		}
	
		return(nLen)
	}
	//}}}
	//{{{ function SourceValue
	function SourceValue(aTemp) {
	var aPickList, nPickList, optionPickList,
		sOperatorDisplay="none", sPickListDisplay="none", sLookupDisplay="none"
	
		if (aTemp[TABLEFIELD_PICKLIST] != " ") {
			sSourceValue="picklist"
			sPickListDisplay="block"
			aPickList=aTemp[TABLEFIELD_PICKLIST].split(",")
	
			with (document.frmSchedView.picklist) {
				while (options.length != 1)
					if (options[options.length - 1].value != " ")
						options[options.length - 1]=null
	
				for (nPickList=0; nPickList < aPickList.length; nPickList++) {
					optionPickList=new Option(aPickList[nPickList], aPickList[nPickList])
					options[options.length]=optionPickList
				}
			}
		} else if (aTemp[TABLEFIELD_LKUPKEY] != " ") {
				sSourceValue="lookup"
				sLookupDisplay="block"
				document.frmSchedView.lookupkey.size=aTemp[TABLEFIELD_LKUPKEYSIZE]
				document.frmSchedView.lookupkey.value=""
				document.frmSchedView.lookupdesc.value=""
				document.frmSchedView.lookupkey.tablename=aTemp[TABLEFIELD_LKUPTABLE]
				document.frmSchedView.lookupkey.fieldtype=aTemp[TABLEFIELD_TYPE]
				document.frmSchedView.lookupkey.fieldname=aTemp[TABLEFIELD_LKUPKEY]
				document.frmSchedView.lookupdesc.fieldname=aTemp[TABLEFIELD_LKUPRESULT]
		} else {
			sOperatorDisplay="block"
			sSourceValue="cnd_operator"
		}
		document.getElementById("svoperator").style.display=sOperatorDisplay
		document.getElementById("svpicklist").style.display=sPickListDisplay
		document.getElementById("svlookup").style.display=sLookupDisplay
		//document.all.svoperator.style.display=sOperatorDisplay
		//document.all.svpicklist.style.display=sPickListDisplay
		//document.all.svlookup.style.display=sLookupDisplay
	}
	//}}}
	//{{{ function ToggleOperator
	function ToggleOperator(sOperator) {
	var lTrue
		if (sOperator == "cnd_operator")
			lTrue=(document.frmSchedView.cnd_operator.selectedIndex == 0)
		else
			if (sOperator == "picklist")
				lTrue=(document.frmSchedView.picklist.selectedIndex == 0)
			else
				lTrue=(document.frmSchedView.lookupkey.value == "")
	
		if (lTrue) {
			if (sOperator == "cnd_operator")
				document.frmSchedView.cnd_operator.selectedIndex=1
			else
				if (sOperator == "picklist")
					document.frmSchedView.picklist.selectedIndex=1
		}
	}
	//}}}
	//{{{ function GetColumnType
	function GetColumnType(sTableName, sFieldName) {
	var oTableField=document.frmSchedView.tablefield, nCnt, sDataType="", aTemp
	
		for (nCnt=0; nCnt < oTableField.options.length; nCnt++) {
			aTemp=oTableField.options[nCnt].value.split(DELIMITER)
	
			if (aTemp[TABLEFIELD_TABLE] == sTableName &&
				aTemp[TABLEFIELD_FIELD] == sFieldName) {
				sDataType=aTemp[TABLEFIELD_TYPE]
				break
			}
		}
		return (sDataType.toLowerCase())
	}
	//}}}
	//{{{ function AddCondition
	function AddCondition() {
	var oCnd_Value=document.frmSchedView.cnd_value,
		oCondition=document.frmSchedView.condition, optionCondition,
		oSourceTable=document.frmSchedView.sourcetable,
		oSourceField=document.frmSchedView.sourcefield,
		sSourceField=oSourceField.options[oSourceField.selectedIndex].value,
		lAddCondition=false, sAliasSource, sAliasJoining, sText, sValue,
		sTextEqualTo, sValueEqualTo, sCnd_Operator,
		sCnd_Value,	sCnd_JoinOperator, sPriorityNo, aTemp, nPriorityNo, rTemp,
		sSourceType, sJoiningType, lSameType
	
		if (oSourceField.options.length == 0)
			alert("Source field is empty.")
		else {
			//sSourceValue="cnd_operator"
			sSourceType=GetColumnType(oSourceTable.options[oSourceTable.selectedIndex].value, sSourceField)
	
			rTemp=sSourceField.split(DELIMITER)
			//sSourceType = rTemp[1]
			sSourceField = rTemp[0]
	
			if (sSourceValue == "cnd_operator") {
				sCnd_Operator=document.frmSchedView.cnd_operator.options[document.frmSchedView.cnd_operator.selectedIndex].value
				//sCnd_Value	=oCnd_Value.value.replace(" ", "")
				sCnd_Value=Trim(oCnd_Value.value)
	
				if (sCnd_Operator == " ")
					alert("Please select operator.")
				else
					if ((sSourceType == "ftdatetime") && (!CheckDate(oCnd_Value))) {
						alert("Cannot convert value to date.")
						oCnd_Value.focus()
					} else {
						if (sSourceType == "ftint" && sSourceType == "ftfloat"){
							if (isNaN(parseFloat(sCnd_Value))) {
								alert("Cannot convert value to number.")
								oCnd_Value.focus()
							} else {
								oCnd_Value.value=parseFloat(sCnd_Value).toString()
								sCnd_Value=oCnd_Value.value
								lAddCondition=true
							}
						} else {
							lAddCondition=true
						}
					}
				} else {
					lAddCondition=true
					sCnd_Operator="="
	
					if (sSourceValue == "picklist") {
						sCnd_Value=document.frmSchedView.picklist.options[document.frmSchedView.picklist.selectedIndex].value.replace(" ", "")
					} else {
						sCnd_Value=document.frmSchedView.lookupkey.value.replace(" ", "")
					}
				}
	
			sCnd_Value=(sCnd_Value == "") ? "''" : sCnd_Value
	
			if (lAddCondition) {
				sTextEqualTo=sCnd_Operator + " " + ((sCnd_Value == "") ? "''" : sCnd_Value)
				sValueEqualTo=((sCnd_Value == "") ? " " : sCnd_Value) + DELIMITER + " "
			}
	
		}
	
		if (lAddCondition) {
			if (nConditionLen == 0){
				sPriorityNo=nConditionLen.toString()
			} else {
				aTemp=oCondition.options[nConditionLen-1].value.split(DELIMITER)
				nPriorityNo=parseInt(aTemp[CONDITION_PRIORITYNO]) + 1
				sPriorityNo=nPriorityNo.toString()
			}
	
			sCnd_JoinOperator= (document.frmSchedView.cnd_joinoperator[0].checked) ?
				document.frmSchedView.cnd_joinoperator[0].value :
				document.frmSchedView.cnd_joinoperator[1].value
			sCnd_JoinOperator = " ";
			sAliasSource=GetAlias(oSourceTable.value)
			sText=sAliasSource + "." + sSourceField + " " +
				  sTextEqualTo + " " + sCnd_JoinOperator
			sValue=sPriorityNo + DELIMITER +
				   sAliasSource + DELIMITER + sSourceField + DELIMITER +
				   sCnd_Operator + DELIMITER + sValueEqualTo + DELIMITER + sCnd_JoinOperator +
				   DELIMITER + " " + DELIMITER + " "
			optionCondition=new Option(sText, sValue)
			oCondition.options[nConditionLen++]=optionCondition	
		}
	}
	//}}}
	//{{{ function SubmitNow
	function SubmitNow() {
	var oSelectedTable=document.frmSchedView.selectedtable,
		oCondition=document.frmSchedView.condition,
		nCnt, lSubmit=false
	
		if (document.frmSchedView.btnUserFilterBack.backvalue != 1) {
			lSubmit=true
			SelectMultiple(nConditionLen, oCondition)
		} else {
			lSubmit=true
		}
		if (lSubmit)
			lSubmit = validateOperator();
		return (lSubmit)
	}
	//}}}
	//{{{ function SelectMultiple
	function SelectMultiple(nLen, oItem) {
	var nCnt
	
		for (nCnt=0; nCnt < nLen; nCnt++) {
			if (!oItem.options[nCnt].selected)
				oItem.options[nCnt].selected=true
		}
	}
	//}}}
	//{{{ function ValidateFieldOrTable
	function ValidateFieldOrTable(nLen, oSelect, nIndex) {
	var oCondition=document.frmSchedView.condition, sAliases="",
		nCnt, aTemp, lSubmit=true, nInnCnt
	
		for (nCnt=0; nCnt < nLen; nCnt++) {
			aTemp=new Array()
			aTemp=oSelect.options[nCnt].value.split(DELIMITER)
	
			if (sAliases.indexOf(aTemp[nIndex]) == -1)
				sAliases=sAliases + aTemp[nIndex]
		}
	
		// Check selected field or table versus condition
		if (sAliases.length > 1) {
			for (nCnt=0; nCnt < sAliases.length; nCnt++) {
				lSubmit=true
	
				for (nInnCnt=0; nInnCnt < nConditionLen; nInnCnt++) {
					aTemp=new Array()
					aTemp=oCondition.options[nInnCnt].value.split(DELIMITER)
				}
	
				if (!lSubmit) {
					alert("Error in condition.")
					break
				}
			}
		}
	
	return (lSubmit)
	}
	//}}}
	//{{{ function ChangeSourceValue---
	function ChangeSourceValue() {
	var nCnt, aTemp, oTableField=document.frmSchedView.tablefield;
	
		for (nCnt=0; nCnt < oTableField.options.length; nCnt++) {
			aTemp=oTableField.options[nCnt].value.split(DELIMITER)
	
			if ( (aTemp[TABLEFIELD_TABLE] == document.frmSchedView.sourcetable.value) &&
			   (aTemp[TABLEFIELD_FIELD] == document.frmSchedView.sourcefield.value) ) {
			   // use code below to equal the value of sourcefield to enable d checkdate.js & Look-ups feature... by winston
			   //(aTemp[TABLEFIELD_FIELD] + "~" + aTemp[TABLEFIELD_TYPE] == document.frmSchedView.sourcefield.value) ) {
				SourceValue(aTemp)
				break
			}
		}
	}
	//}}}
	//{{{ function GenerateLookupParams
	function GenerateLookupParams() {
	var nCnt, aTemp, sLevel="", sFldProp,
		oAvailableTable=document.frmSchedView.availabletable
	
		// Get table level
		for (nCnt=0; nCnt < oAvailableTable.options.length; nCnt++) {
			aTemp=oAvailableTable.options[nCnt].value.split(DELIMITER)
	
			if (aTemp[AVAILABLETABLE_TABLE] == document.frmSchedView.sourcetable.value) {
				sLevel=aTemp[AVAILABLETABLE_LEVEL]
				break
			}
		}
	
		if ((sLevel != "") && (sLevel != " ")) {
			sFldProp=document.frmSchedView.lookupkey.fieldname + "~" + document.frmSchedView.lookupkey.fieldname + "~" + document.frmSchedView.lookupkey.fieldtype + "," +
						  document.frmSchedView.lookupdesc.fieldname + "~" + document.frmSchedView.lookupdesc.fieldname + "~ftstring"
	
			open("../../../common/poplookup.cfm" +
			"?tl=" + sLevel +
			"&tn=" + document.frmSchedView.lookupkey.tablename +
			"&fn=lookupkey" +
			"&desc=lookupdesc" +
			"&frm=frmUserFilter" +
			"&nonull=Y" +
			"&fldprop=" + sFldProp +
			"&fldfn=" + document.frmSchedView.lookupkey.fieldname +
			"&flddesc=" + document.frmSchedView.lookupdesc.fieldname,
			"LookupWindow", "width=690,height=330,ScrollBars=Yes,Resizable=Yes")
		} else
			alert("Table has no database level.")
	}
	//}}}
	//{{{ function GroupExpression
	
	function GroupExpression() {
		var oCondition=document.frmSchedView.condition, nCnt, nStartGroup=-1, nEndGroup=-1,
		aTemp, lDiffType=false, sCurrentLevel=""
		for (nCnt=0; nCnt < nConditionLen; nCnt++)
			if (oCondition.options[nCnt].selected) {
				if (nStartGroup == -1) {
					nStartGroup=nCnt
					nEndGroup=nCnt
				} else
					nEndGroup=nCnt
			}
	
		if (nStartGroup == -1)
			alert("Please select at least one(1) condition.")
		else {
			for (nCnt=nStartGroup; nCnt <= nEndGroup; nCnt++) {
				aTemp=oCondition.options[nCnt].value.split(DELIMITER)
				sCurrentLevel=(sCurrentLevel == "") ? GetDatabaseLevel(aTemp[CONDITION_ALIASSOURCE]) : sCurrentLevel
	
				if (sCurrentLevel == GetDatabaseLevel(aTemp[CONDITION_ALIASSOURCE])) {
				} else {
					lDiffType=true
					break
				}
			}
	
			if (lDiffType)
				alert("Cannot group expression with tables of different database level.")
			else {
				aTemp=oCondition.options[nStartGroup].value.split(DELIMITER)
	
				if (aTemp[CONDITION_GROUPSTART] == " ")
					aTemp[CONDITION_GROUPSTART]="("
				else
					aTemp[CONDITION_GROUPSTART]=aTemp[CONDITION_GROUPSTART] + "("
	
				oCondition.options[nStartGroup].value=ComposeValue(aTemp)
				oCondition.options[nStartGroup].text="( " + oCondition.options[nStartGroup].text
	
				aTemp=oCondition.options[nEndGroup].value.split(DELIMITER)
	
				if (aTemp[CONDITION_GROUPEND] == " ")
					aTemp[CONDITION_GROUPEND]=")"
				else
					aTemp[CONDITION_GROUPEND]=aTemp[CONDITION_GROUPEND] + ")"
	
				oCondition.options[nEndGroup].value=ComposeValue(aTemp)
				oCondition.options[nEndGroup].text=oCondition.options[nEndGroup].text + " )"
			}
		}
	}
	
	function GroupExpression_2() {
	var oCondition=document.frmSchedView.condition, nCnt, nStartGroup=-1, nEndGroup=-1,
		aTemp, lDiffType=false, sCurrentLevel=""
		alert("x" + nConditionLen);
		for (nCnt=0; nCnt < nConditionLen; nCnt++)
			if (oCondition.options[nCnt].selected) {
				if (nStartGroup == -1) {
					nStartGroup=nCnt
					nEndGroup=nCnt
				} else
					nEndGroup=nCnt
			}
	
		if (nStartGroup == -1)
			alert("Please select at least one(1) condition.")
		else {
			for (nCnt=nStartGroup; nCnt <= nEndGroup; nCnt++) {
				if (nCnt ==  nStartGroup) {
					aTemp=oCondition.options[nCnt].value.split(DELIMITER)
					if (aTemp[CONDITION_GROUPSTART] == " ")
						aTemp[CONDITION_GROUPSTART]="("
					else
						aTemp[CONDITION_GROUPSTART]=aTemp[CONDITION_GROUPSTART] + "("
					oCondition.options[nStartGroup].value=ComposeValue(aTemp)
					oCondition.options[nStartGroup].text="( " + oCondition.options[nStartGroup].text
				}
				else if (nCnt == nEndGroup) {
					aTemp=oCondition.options[nCnt].value.split(DELIMITER)
					if (aTemp[CONDITION_GROUPEND] == " ")
						aTemp[CONDITION_GROUPEND]=")"
					else
						aTemp[CONDITION_GROUPEND]=aTemp[CONDITION_GROUPEND] + ")"
					oCondition.options[nEndGroup].value=ComposeValue(aTemp)
					oCondition.options[nEndGroup].text=oCondition.options[nEndGroup].text + " )"
				}
			}
		}
	}
	//}}}
	//{{{ function RemoveGrouping
	function RemoveGrouping() {
	var oCondition=document.frmSchedView.condition, nCnt, aTemp, sText, re1=/\( /g, re2=/ \)/g
	
		for (nCnt=0; nCnt < nConditionLen; nCnt++) {
			aTemp=oCondition.options[nCnt].value.split(DELIMITER)
			aTemp[CONDITION_GROUPSTART]=" "
			aTemp[CONDITION_GROUPEND]=" "
	
			oCondition.options[nCnt].value=ComposeValue(aTemp)
			oCondition.options[nCnt].text=oCondition.options[nCnt].text.replace(re1, "")
			oCondition.options[nCnt].text=oCondition.options[nCnt].text.replace(re2, "")
		}
	}
	//}}}
	//{{{ function RemoveCondition
	function RemoveCondition() {
	var oCondition=document.frmSchedView.condition, nCnt, aTemp, lFinish, lRemoveGrouping=false,
		sGroupStart, sEndStart
	
		while (true) {
			lFinish=true
	
			for (nCnt=0; nCnt < nConditionLen; nCnt++) {
				if (oCondition.options[nCnt].selected) {
					aTemp=oCondition.options[nCnt].value.split(DELIMITER)
					sGroupStart=aTemp[CONDITION_GROUPSTART].replace(/ /g, "")
					sEndStart=aTemp[CONDITION_GROUPEND].replace(/ /g, "")
	
					if (sGroupStart.length != sEndStart.length) {
	
						if (confirm("Deleting this condition will remove the grouping. \n" + oCondition.options[nCnt].text)) {
							oCondition.options[nCnt]=null
							nConditionLen--
							lFinish=false
							lRemoveGrouping=true
							break
						} else
							oCondition.options[nCnt].selected=false
	
					} else {
						oCondition.options[nCnt]=null
						nConditionLen--
						lFinish=false
						break
					} // if condition has grouping
				} // if selected
			} // for
	
			if (lFinish)
				break
		} // while
	
		if (lRemoveGrouping)
			RemoveGrouping()
	}
	//}}}
	//{{{ function MoveUp
	function MoveUp() {
	var nRows=1, oCondition=document.frmSchedView.condition, nCnt, aTemp, sSelectText,
		nInnerCnt, sMoveText, nPriorityNo, nStopMove, aSelectTemp, lHasGrouping=false
	
		for (nCnt=0; nCnt < nConditionLen; nCnt++)
			if (oCondition.options[nCnt].selected && nCnt != 0) {
				nRows=prompt("Enter the no. of Rows to move up \nCONDITION: " + oCondition.options[nCnt].text + " \n", nRows)
	
				if (nRows != 0 && nRows != null) {
					nStopMove=(nCnt - nRows < 0) ? 0 : nCnt - nRows
					aSelectTemp=oCondition.options[nCnt].value.split(DELIMITER)
					sSelectText=oCondition.options[nCnt].text
					// Check if items to move has grouping
					if (aSelectTemp[CONDITION_GROUPSTART] == " " && aSelectTemp[CONDITION_GROUPEND] == " ") {
						for (nInnerCnt=nCnt-1; nInnerCnt >= nStopMove; nInnerCnt--) {
							aTemp=oCondition.options[nInnerCnt].value.split(DELIMITER)
	
							if (aTemp[CONDITION_GROUPSTART] != " " || aTemp[CONDITION_GROUPEND] != " ") {
								lHasGrouping=true
								break
							}
						}
					} else
						lHasGrouping=true
	
					if (!lHasGrouping || confirm("Moving this condition will remove the grouping. \n" + sSelectText)) {
						// Move down bypassed items incrementing its priority no by 1
						for (nInnerCnt=nCnt-1; nInnerCnt >= nStopMove; nInnerCnt--) {
							sMoveText=oCondition.options[nInnerCnt].text
							aTemp=oCondition.options[nInnerCnt].value.split(DELIMITER)
	
							nPriorityNo=parseInt(aTemp[CONDITION_PRIORITYNO]) + 1
							aTemp[CONDITION_PRIORITYNO]=nPriorityNo.toString()
							oCondition.options[nInnerCnt + 1].value=ComposeValue(aTemp)
							oCondition.options[nInnerCnt + 1].text=sMoveText
						}
	
						// Move up selected item decrementing its priority no. depending on no. of movements
						nPriorityNo--
						aSelectTemp[CONDITION_PRIORITYNO]=nPriorityNo.toString()
						oCondition.options[nStopMove].value=ComposeValue(aSelectTemp)
						oCondition.options[nStopMove].text=sSelectText
	
						if (lHasGrouping)
							RemoveGrouping()
					}
				}
				break
			}
	}
	//}}}
	//{{{ function MoveUp2
	function MoveUp2(oObject, nObjectLen) {
	var nRows=1, nCnt, sSelectText,	sSelectValue,
		nInnerCnt, nStopMove, sMoveText, sMoveValue
	
		for (nCnt=0; nCnt < nObjectLen; nCnt++)
			if (oObject.options[nCnt].selected && nCnt != 0) {
				nRows=prompt("Enter the no. of Rows to move up \nField: " + oObject.options[nCnt].text + " \n", nRows)
	
				if (nRows != 0 && nRows != null) {
					nStopMove=(nCnt - nRows < 0) ? 0 : nCnt - nRows
					sSelectValue=oObject.options[nCnt].value
					sSelectText=oObject.options[nCnt].text
	
					// Move down bypassed items incrementing its priority no by 1
					for (nInnerCnt=nCnt-1; nInnerCnt >= nStopMove; nInnerCnt--) {
						sMoveText=oObject.options[nInnerCnt].text
						sMoveValue=oObject.options[nInnerCnt].value
						oObject.options[nInnerCnt + 1].value=sMoveValue
						oObject.options[nInnerCnt + 1].text=sMoveText
					}
	
					// Move up selected item decrementing its priority no. depending on no. of movements
					oObject.options[nStopMove].value=sSelectValue
					oObject.options[nStopMove].text=sSelectText
				}
				break
			}
	}
	//}}}
	//{{{ function MoveDown
	function MoveDown() {
	var nRows=1, oCondition=document.frmSchedView.condition, nCnt, aTemp, sSelectText,
		nInnerCnt, sMoveText, nPriorityNo, nStopMove, aSelectTemp, lHasGrouping=false
	
		for (nCnt=0; nCnt < nConditionLen; nCnt++)
			if (oCondition.options[nCnt].selected && nCnt != (nConditionLen - 1)) {
				nRows=prompt("Enter the no. of Rows to move down \nCONDITION: " + oCondition.options[nCnt].text + " \n", nRows)
	
				if (nRows != 0 && nRows != null) {
					nStopMove=(nCnt + nRows > (nConditionLen - 1)) ? (nConditionLen - 1) : nCnt + nRows
					aSelectTemp=oCondition.options[nCnt].value.split(DELIMITER)
					sSelectText=oCondition.options[nCnt].text
					// Check if items to move has grouping
					if (aSelectTemp[CONDITION_GROUPSTART] == " " && aSelectTemp[CONDITION_GROUPEND] == " ") {
						for (nInnerCnt=nCnt+1; nInnerCnt <= nStopMove; nInnerCnt++) {
							aTemp=oCondition.options[nInnerCnt].value.split(DELIMITER)
	
							if (aTemp[CONDITION_GROUPSTART] != " " || aTemp[CONDITION_GROUPEND] != " ") {
								lHasGrouping=true
								break
							}
						}
					} else
						lHasGrouping=true
	
					if (!lHasGrouping || confirm("Moving this condition will remove the grouping. \n" + sSelectText)) {
						// Move up bypassed items decrementing its priority no by 1
						for (nInnerCnt=nCnt+1; nInnerCnt <= nStopMove; nInnerCnt++) {
							sMoveText=oCondition.options[nInnerCnt].text
							aTemp=oCondition.options[nInnerCnt].value.split(DELIMITER)
	
							nPriorityNo=parseInt(aTemp[CONDITION_PRIORITYNO]) - 1
							aTemp[CONDITION_PRIORITYNO]=nPriorityNo.toString()
							oCondition.options[nInnerCnt - 1].value=ComposeValue(aTemp)
							oCondition.options[nInnerCnt - 1].text=sMoveText
						}
	
						// Move down selected item incrementing its priority no. depending on no. of movements
						nPriorityNo++
						aSelectTemp[CONDITION_PRIORITYNO]=nPriorityNo.toString()
						oCondition.options[nStopMove].value=ComposeValue(aSelectTemp)
						oCondition.options[nStopMove].text=sSelectText
	
						if (lHasGrouping)
							RemoveGrouping()
					}
				}
				break
			}
	}
	//}}}
	//{{{ function MoveDown2
	function MoveDown2(oObject, nObjectLen) {
	var nRows=1, nCnt, sMoveValue, sSelectText,
		nInnerCnt, sMoveText, nStopMove, sSelectValue
	
		for (nCnt=0; nCnt < nObjectLen; nCnt++)
			if (oObject.options[nCnt].selected && nCnt != (nObjectLen - 1)) {
				nRows=prompt("Enter the no. of Rows to move down \nField: " + oObject.options[nCnt].text + " \n", nRows)
	
				if (nRows != 0 && nRows != null) {
					nStopMove=(nCnt + nRows > (nObjectLen - 1)) ? (nObjectLen - 1) : nCnt + nRows
					sSelectValue=oObject.options[nCnt].value
					sSelectText=oObject.options[nCnt].text
	
					// Move up bypassed items decrementing its priority no by 1
					for (nInnerCnt=nCnt+1; nInnerCnt <= nStopMove; nInnerCnt++) {
						sMoveText=oObject.options[nInnerCnt].text
						sMoveValue=oObject.options[nInnerCnt].value.split(DELIMITER)
						oObject.options[nInnerCnt - 1].value=sMoveValue
						oObject.options[nInnerCnt - 1].text=sMoveText
					}
	
					// Move down selected item incrementing its priority no. depending on no. of movements
					oObject.options[nStopMove].value=sSelectValue
					oObject.options[nStopMove].text=sSelectText
				}
				break
			}
	}
	//}}}
	//{{{ function ComposeValue
	function ComposeValue(aTemp) {
	var nCnt, sValue="", sDelimiter=""
	
		for (nCnt=0; nCnt < aTemp.length; nCnt++) {
			sValue=sValue + sDelimiter + aTemp[nCnt]
			sDelimiter=DELIMITER
		}
	
	return (sValue)
	}
	//}}}
	//{{{ function GetDatabaseLevel
	function GetDatabaseLevel(sAlias) {
	var nCnt, oSelectedTable=document.frmSchedView.selectedtable, aTemp, sLevel=""
	
		for (nCnt=0; nCnt < oSelectedTable.length; nCnt++) {
			aTemp=oSelectedTable.options[nCnt].value.split(DELIMITER)
	
			if (aTemp[SELECTEDTABLE_ALIAS] == sAlias) {
				sLevel=aTemp[SELECTEDTABLE_LEVEL]
				break
			}
		}
	
	return (sLevel)
	}
	//}}}
	//{{{ function AddGroupHeader
	function AddGroupHeader() {
	var nCnt, sAliasFldName, lGroupHeadExist=false, optionGroupHeader,
		aTemp
	
		with (document.frmSchedView) {
			if (headertable.selectedIndex != -1) {
				sAliasFldName=headertable.options[headertable.selectedIndex].value
	
				for (nCnt=0; nCnt < nGroupHeaderLen; nCnt++) {
					aTemp=groupheader.options[nCnt].value.split(DELIMITER)
					if (aTemp[GROUPHEADER_FIELDALIAS] == sAliasFldName) {
						lGroupHeadExist=true
						break
					}
				}
	
				if (!lGroupHeadExist) {
					optionGroupHeader=new Option(sAliasFldName, sAliasFldName)
					groupheader.options[nGroupHeaderLen++]=optionGroupHeader
				}
			}
		}
	}
	//}}}
	//{{{ function RemoveGroupHeader
	function RemoveGroupHeader() {
		nGroupHeaderLen=RemoveFromList(document.frmSchedView.groupheader, nGroupHeaderLen)
	}
	//}}}
	//{{{ function AddGroupFooter
	function AddGroupFooter() {
	var nCnt, optionGroupFooter, sText, sValue, sAggregate, sDataType,
		lGo=false, sTableName, sColumnName, sAlias
	
		with (document.frmSchedView) {
			for (nCnt=0; nCnt < nGroupHeaderLen; nCnt++) {
				if (groupheader.options[nCnt].selected) {
					lGo=true
					break
				}
			}
	
			if (!lGo)
				alert("Please add/select group header first.")
			else
				if (groupfootercaption.value == "")
					alert("Caption for group footer is empty.")
				else
					if (footertable.selectedIndex != -1) {
						sAggregate=groupfooteraggregate.options[groupfooteraggregate.selectedIndex].value
						sAlias=footertable.options[footertable.selectedIndex].value.substring(0, 1)
						sTableName=GetTableName(sAlias)
						sColumnName=footertable.options[footertable.selectedIndex].value.substring(0, footertable.options[footertable.selectedIndex].value.length)
						sDataType=GetColumnType(sTableName, sColumnName)
	
						if ( (sAggregate == "sum" || sAggregate == "avg") &&
							 (sDataType == "ftstring" || sDataType == "ftcombo" || sDataType == "ftdatetime") ) {
							alert("Field must be of numeric type.")
						} else {
							sValue=groupfootercaption.value + DELIMITER +
								sAlias + DELIMITER +
								sColumnName + DELIMITER + sAggregate
							sText=groupfootercaption.value + ": " +
								sAggregate + "(" +
								sAlias + sColumnName + ")"
							optionGroupFooter=new Option(sText, sValue)
							groupfooter.options[nGroupFooterLen++]=optionGroupFooter
							ComposeFooter()
						} // datatype has been validated
					}
		}
	}
	//}}}
	//{{{ function RemoveGroupFooter
	function RemoveGroupFooter() {
		nGroupFooterLen=RemoveFromList(document.frmSchedView.groupfooter, nGroupFooterLen)
	}
	//}}}
	//{{{ function ComposeFooter
	function ComposeFooter() {
	var nCnt, nInnCnt, aTemp, sValue, aFootTemp
	
		with (document.frmSchedView) {
			for (nCnt=0; nCnt < nGroupHeaderLen; nCnt++) {
				if (groupheader.options[nCnt].selected) {
					aTemp=groupheader.options[nCnt].value.split(DELIMITER)
					sValue=aTemp[GROUPHEADER_FIELDALIAS]
	
					for (nInnCnt=0; nInnCnt < nGroupFooterLen; nInnCnt++) {
						aFootTemp=groupfooter.options[nInnCnt].value.split(DELIMITER)
						sValue=sValue + DELIMITER +
							aFootTemp[GROUPFOOTER_CAPTION] + DELIMITER +
							aFootTemp[GROUPFOOTER_ALIAS] + DELIMITER +
							aFootTemp[GROUPFOOTER_FIELD] + DELIMITER +
							aFootTemp[GROUPFOOTER_AGGREGATE]
					} // apply all footers
	
					groupheader.options[nCnt].value=sValue
				} // apply group footer only to selected group header
			}
		}
	}
	//}}}
	//{{{ function UpdateFooter
	function UpdateFooter() {
	var lUpdated=false, aTemp, nCnt, nInnCnt, nMod,
		nIndex1, nIndex2, nIndex3, nIndex4, nLoopCnt=0, optionGroupFooter
	
		with (document.frmSchedView) {
			for (nCnt=0; nCnt < nGroupHeaderLen; nCnt++) {
				if (groupheader.options[nCnt].selected) {
	
					if (!lUpdated) {
						lUpdated=true
						nGroupFooterLen=ClearSelectItems(nGroupFooterLen, groupfooter)
						aTemp=groupheader.options[nCnt].value.split(DELIMITER)
	
						if (aTemp.length > 1) {
							nMod=(aTemp.length - 1) / GROUPHEADER_FUNCTION
	
							for (nInnCnt=1; nInnCnt <= nMod; nInnCnt++) {
								nIndex1=GROUPHEADER_CAPTION + nLoopCnt
								nIndex2=GROUPHEADER_ALIAS + nLoopCnt
								nIndex3=GROUPHEADER_FIELD + nLoopCnt
								nIndex4=GROUPHEADER_FUNCTION + nLoopCnt
	
								sValue=aTemp[nIndex1] + DELIMITER +
									aTemp[nIndex2] + DELIMITER +
									aTemp[nIndex3] + DELIMITER +
									aTemp[nIndex4]
								sText=aTemp[nIndex1] + ": " +
									aTemp[nIndex4] + "(" +
									aTemp[nIndex2] +
									aTemp[nIndex3] + ")"
								optionGroupFooter=new Option(sText, sValue)
								groupfooter.options[nGroupFooterLen++]=optionGroupFooter
								nLoopCnt=nLoopCnt + 4
							}
						}
					} else
						groupheader.options[nCnt].selected=false
				}
			}
		}
	}
	//}}}
	//{{{ function AddPageFooter
	function AddPageFooter() {
	var sAggregate, sDataType, optionPageFooter,
		sAlias, sTableName, sColumnName
	
		with (document.frmSchedView) {
			if (pagecaption.value == "")
				alert("Caption for page footer is empty.")
			else
				if (pagetable.selectedIndex != -1) {
					sAggregate=pageaggregate.options[pageaggregate.selectedIndex].value
					sAlias=pagetable.options[pagetable.selectedIndex].value.substring(0, 1)
					sTableName=GetTableName(sAlias)
					sColumnName=pagetable.options[pagetable.selectedIndex].value.substring(0, pagetable.options[pagetable.selectedIndex].value.length)
					sDataType=GetColumnType(sTableName, sColumnName)
	
					if ( (sAggregate == "sum" || sAggregate == "avg") &&
						 (sDataType == "ftstring" || sDataType == "ftcombo" || sDataType == "ftdatetime") ) {
						alert("Field must be of numeric type.")
					} else {
						sValue=sAlias + DELIMITER + sColumnName + DELIMITER +
							pagecaption.value + DELIMITER + sAggregate
						sText=pagecaption.value + ": " +
							sAggregate + "(" + sAlias + sColumnName + ")"
						optionPageFooter=new Option(sText, sValue)
						pagefooter.options[nPageFooterLen++]=optionPageFooter
					}
				}
		}
	}
	//}}}
	//{{{ function RemovePageFooter
	function RemovePageFooter() {
		nPageFooterLen=RemoveFromList(document.frmSchedView.pagefooter, nPageFooterLen)
	}
	//}}}
	//{{{ function AddGrandFooter
	function AddGrandFooter() {
	var sAggregate, sDataType, optionGrandFooter,
		sAlias, sTableName, sColumnName
	
		with (document.frmSchedView) {
			if (grandcaption.value == "")
				alert("Caption for grand footer is empty.")
			else
				if (grandtable.selectedIndex != -1) {
					sAggregate=grandaggregate.options[grandaggregate.selectedIndex].value
					sAlias=grandtable.options[grandtable.selectedIndex].value.substring(0, 1)
					sTableName=GetTableName(sAlias)
					sColumnName=grandtable.options[grandtable.selectedIndex].value.substring(0, grandtable.options[grandtable.selectedIndex].value.length)
					sDataType=GetColumnType(sTableName, sColumnName)
	
					if ( (sAggregate == "sum" || sAggregate == "avg") &&
						 (sDataType == "ftstring" || sDataType == "ftcombo" || sDataType == "ftdatetime") ) {
						alert("Field must be of numeric type.")
					} else {
						sValue=sAlias + DELIMITER + sColumnName +
							DELIMITER + grandcaption.value + DELIMITER +
							sAggregate
						sText=grandcaption.value + ": " +
							sAggregate + "(" + sAlias + sColumnName + ")"
						optionGrandFooter=new Option(sText, sValue)
						grandfooter.options[nGrandFooterLen++]=optionGrandFooter
					}
				}
		}
	}
	//}}}
	//{{{ function RemoveGrandFooter
	function RemoveGrandFooter() {
		nGrandFooterLen=RemoveFromList(document.frmSchedView.grandfooter, nGrandFooterLen)
	}
	//}}}
	//{{{ function ShowFieldProperty
	function ShowFieldProperty() {
	var nCnt, aTemp, sFunction, sWrapOn
	
		with (document.frmSchedView.selectedfield) {
			for (nCnt=0; nCnt < nSelectedFieldLen; nCnt++) {
				if (options[nCnt].selected) {
					aTemp=options[nCnt].value.split(DELIMITER)
	
					if (aTemp[SELECTEDFIELD_DATECONVFUNC] == "year")
						sFunction="Year of Date"
					else
						if (aTemp[SELECTEDFIELD_DATECONVFUNC] == "month")
							sFunction="Month of Date"
						else
							if (aTemp[SELECTEDFIELD_DATECONVFUNC] == "day")
								sFunction="Day of Date"
							else
								sFunction="No. of Years"
	
					if (aTemp[SELECTEDFIELD_WRAPON] == "0")
						sWrapOn="Don't Wrap"
					else
						if (aTemp[SELECTEDFIELD_WRAPON] == "2")
							sWrapOn="2nd Word"
						else
							if (aTemp[SELECTEDFIELD_WRAPON] == "3")
								sWrapOn="3rd Word"
							else
								if (aTemp[SELECTEDFIELD_WRAPON] == "4")
									sWrapOn="4th Word"
								else
									sWrapOn="5th Word"
	
					alert("Alias: " + aTemp[SELECTEDFIELD_ALIAS] + "\n" +
						"Field: " + aTemp[SELECTEDFIELD_FIELDNAME] + "\n" +
						"Header Name: " + aTemp[SELECTEDFIELD_HEADERNAME] + "\n" +
						"Aggregate: " + aTemp[SELECTEDFIELD_AGGREGATE] + "\n" +
						"Date Convertion: " + sFunction + "\n" +
						"Number Format: " + aTemp[SELECTEDFIELD_NUMBERFORMAT] + "\n" +
						"Wrap Header Name on: " + sWrapOn + "\n" +
						"Supress Zero: " + aTemp[SELECTEDFIELD_SUPRESSZERO])
				}
			}
		}
	}
	function validateOperator() {
		var lReturn, frm, lstCond,x,sVal
		lReturn = true
		frm = document.frmSchedView
		lstCond = frm.condition
		for(x=0;x<lstCond.options.length-1;x++) {
			sVal = lstCond.options[x].value.split("~");
			if (sVal[6].length<2) {
				alert("Please set operators first.")
				lReturn = false
			}
	
		}
		return lReturn;
	}
	function setOperator() {
		var frm, sltCondition, iSlct, sCnd_JoinOperator, sTxt, sValue,iLst
		frm = document.frmSchedView;
		sltCondition = frm.condition;
		if (sltCondition.options.length > 0) {
			iSlct = sltCondition.selectedIndex;
			sCnd_JoinOperator = (frm.cnd_joinoperator[0].checked) ?
						frm.cnd_joinoperator[0].value :
						frm.cnd_joinoperator[1].value
			sTxt = sltCondition.options[iSlct].text
			sValue = sltCondition.options[iSlct].value.split("~");
			if (sValue[6].length > 1) {
				iLst = sTxt.lastIndexOf(" ");
				sTxt = sTxt.substring(0,iLst);
			}
			sValue[6] = sCnd_JoinOperator;
			sValue = sValue.join("~");
			sltCondition.options[iSlct].value = sValue;
			sltCondition.options[iSlct].text = sTxt + " " + sCnd_JoinOperator;
		}
	}
	//}}}
</script>
